<?php
require_once (dirname(__FILE__) . '/simpletest/autorun.php');
require_once ('currencyScraper.php');

class CurrencyConverterUnitTests extends UnitTestCase {
	private $currencyScraper;
	private $reflectionScraper;

	function setup() {
		$this -> reflectionScraper = new ReflectionClass("currencyScraper");
		$this -> currencyScraper = new currencyScraper();
	}

	function tearDown() {
		unset($this -> currencyScraper);
	}

	/*
	 * Function to test that an invalid request returns......
	 */
	function testGetExchangeRateWithInvalidCurrencyCode() {
		$resultOfQuerry = $this -> currencyScraper -> get_exchange_rate("Fake", 2012, 10);
		$this -> assertFalse($resultOfQuerry);
	}

	/*
	 * Function to test that an valid request returns a JSON file containg the info
	 */
	function testValidateOKCurrencyCode() {
		$method = $this -> reflectionScraper -> getMethod("validateCurrency");
		$method -> setAccessible(true);

		$result = $method -> invoke($this -> currencyScraper, "aud");
		$this -> assertTrue($result);
	}

	function testValidateOKDate() {
		$method = $this -> reflectionScraper -> getMethod("validateDate");
		$method -> setAccessible(true);

		$result = $method -> invoke($this -> currencyScraper, 2010, 12);
		$this -> assertTrue($result);

	}

	/*
	 * Function to test that the JSON file is containing data
	 */
	function testJSON() {
		$testArray = array('currency' => "1 AUD 1.11 2.22 3.33");
		$method = $this -> reflectionScraper -> getMethod("dataToJSON");
		$method -> setAccessible(true);

		$year = $this -> reflectionScraper -> getProperty("m_year") -> setAccessible(true);
		//$year -> setValue($this -> reflectionScraper, 2010);

		$month = $this -> reflectionScraper -> getProperty("m_month") -> setAccessible(true);
		//$month -> setValue($this -> reflectionScraper, 10);

		$result = $method -> invoke($this -> currencyScraper, $testArray);
		$this -> assertTrue($result);
	}

}
?>